package com.artezio.buyndrive.web;

import com.artezio.buyndrive.domain.Users;
import com.artezio.buyndrive.service.CarserviceService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * User: spolyakov
 * Date: 25.07.12
 * Time: 11:38
 */

@Controller
public class CarServiceController {

    protected final Log logger = LogFactory.getLog(CarServiceController.class);

    @Autowired
    private CarserviceService carService;

    @RequestMapping(value = "/service", method = RequestMethod.GET)
    public ModelAndView service(Map<String, Object> map,
                                Model model, HttpServletRequest servletRequest) {

        model.addAttribute("user", new Users());

        try{
            Long id = Long.valueOf(servletRequest.getParameter("id"));
            map.put("carService", carService.findById(id));
        }catch (Exception e){
            logger.error(e);
        }

        logger.info("/service");
        return new ModelAndView("service");

    }

}
